from urllib.request import urlopen
from bs4 import BeautifulSoup as bs
from urllib.request import urlretrieve


url = urlopen('https://www.baidu.cn')
obj = bs(url.read(), 'html.parser')
# title = obj.head.title
# 找到所有img标签
pics = obj.findAll('img')
# URL前没有http：的话，加上
for pic in pics:
    if pic['src'].startswith('//www'):
        pic['src'] = 'http:' + pic['src']
res_url = [i['src'] for i in pics]
count = 1
for i in res_url:
    urlretrieve(i, f'/Users/jinsheng/Desktop/1/{count}.png')
    count += 1
